package com.ting.test.algorithms.递归和动态规划.从左往右的模型;

/**
 * 打印n层汉诺塔从最左边移动到最右边的全部过程
 */
public class 汉诺塔问题解法2 {
    public static void main(String[] args) {
        process(3, "left", "right", "mid");
    }

    private static void process(int n, String from, String to, String other) {
        if (n == 1) {
            //如果是最后一层了，直接打印
            System.out.println("第1层从" + from + " 放到了 " + to);
            return;
        }
        //1.先将1~n-1层整体放到中间
        process(n - 1, from, other, to);
        //2.将最后一层n放到右边，直接打印
        System.out.println("第" + n + "层从" + from + "放到了" + to);
        //3.将1~n-1层放到右边
        process(n - 1, other, to, from);
    }


}
